package com.flymobi.mshop.util.service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import android.util.Log;

import com.flymobi.mshop.util.JsonHttpClient;

/**
 * @author gaoxf
 * 
 */
public class ClsService extends IService {
	public static List<Map<String, Object>> cache;

	public static List<Map<String, Object>> listCls(String fatherId) {
		cache = new ArrayList<Map<String, Object>>();
		Map<String, String> params = new HashMap<String, String>();
		params.put("act", Action.LIST_CLS);
		params.put("id", fatherId);
		JSONArray ja = JsonHttpClient.post(serviceUrl, params);
		if(ja==null){
			return cache;
		}
		Log.d("json", ja.toString());
		int size = ja.length();
		for (int i = 0; i < size; i++) {
			JSONObject jo;
			try {
				jo = ja.getJSONObject(i);
				Map<String, Object> map = new HashMap<String, Object>();
				map.put("id", jo.getString("id"));
				map.put("fatherId", jo.getString("fatherId"));
				map.put("name", jo.getString("name"));
				map.put("subclscount", jo.getString("subclscount"));
				cache.add(map);
			} catch (JSONException e) {
				e.printStackTrace();
			}
		}
		return cache;
	}
}
